<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
        <style>
            #name{
                margin-top: 300px;
            }
        </style>
	</head>
	<body>
        <div id="name"></div>
        <div style="width:10px;height:1000px">a</div>
        <button id="btn">跳转</button>
    </body>
    <script>
        var btn = document.getElementById('btn');
        var a = document.getElementById('name')
        btn.addEventListener('click',function(){
            var top = a.offsetTop
            // location.href = '#name'
            document.body.scrollTop = top
        })
    </script>
</html>